﻿<extend name="Public/content" />
<block name="style">
  <style type="text/css">
    .table>tbody>tr>td{ padding: 4px; vertical-align: middle;}
    body{ background: #fff;}
    .footer {
      width: 100%;
      height: 50px;
      position: fixed;
      bottom: 0;

      left: 0;
      line-height: 50px;
      text-align: right;
      text-align: right;
      border-top: solid 1px #eee;
      padding-right: 10px;
      z-index: 999999999999999;
    }
    .update{width: 180px;height: 180px;border: 1px solid #E0E0E0;border-radius: 2px;}
    .yhpj_main_right_pj5_tpsc{width: 47px;height: 47px;border: 1px solid #ccc;border-radius: 2px;position: relative;margin: 64px auto;}
    .yhpj_main_right_pj5_tpsc>span{height: 16px;width: 22px;margin: 16px 12px 15px 13px;background: url(Public/Admin/images/upload.png) no-repeat;display: block;position: absolute;}
    .yhpj_main_right_pj5_tpsc>input{position: absolute;top: 15px;left: 13px;height: 16px;width: 22px;opacity: 0; filter:alpha(opacity=0);-moz-opacity:0;}
  </style>
</block>
<block name="body">
  <input type="hidden" name="order_id" value="{$order_id}" id="order_id">
  <include file="Public:artdialog" />
  <div class="row">
    <div class="col-md-12">
      <div class="block-web">
        <div class="header">
          <h3 class="content-header">上传身份证图片</if></h3>
        </div>


      </div><!--/block-web-->
    </div><!--/col-md-12-->
  </div>


  <div class="row">
   <div class="col-xs-12">             
    <form class="form-horizontal"   id="card_form" enctype="multipart/form-data">
     <input type="hidden" name="source_order_sn" value="{$source_order_sn}" id="source_order_sn">
      <input type="hidden" name="idcard_img" value="" id="idcard_img">
       <input type="hidden" name="idcardanti_img" value="" id="idcardanti_img">
     <div class="form-group">
      <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 身份证号： </label>
      <div class="col-sm-9">
        <input type="text" id="idcard" name="idcard"  placeholder="请输入身份证号" onblur="check_old_pwd(this)"   class="col-xs-10 col-sm-5">
        <span  style="display:none"> <i class="icon-ok green" ></i></span>

      </div>
    </div> 
    <div class="form-group">
      <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 上传身份证图片 </label>
      <div class="col-sm-4">
       <input type="button"  class="btn btn-info" value="身份证正面照" size="30"  onclick="f.click()"  /> 
       <input type="file" id="f"   name="f" style="position:absolute; filter:alpha(opacity=0); opacity:0; width:30px; " size="1" />
     </div>
     <div class="col-sm-4">
      <input type="button"  class="btn btn-info" value="身份证反面照" size="30"   onclick="f2.click()" />
      <input type="file" id="f2"   name="f2" style="position:absolute; filter:alpha(opacity=0); opacity:0; width:30px; " size="1" />
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-3"></div>
    <div class="col-sm-4">
     <div class="update just"><div class="yhpj_main_right_pj5_tpsc"><span></span><input type="hidden" name="" id="" value="" /></div></div>
   </div>
    <div class="col-sm-4">
     <div class="update back"><div class="yhpj_main_right_pj5_tpsc"><span></span><input type="hidden" name="" id="" value="" /></div></div>
   </div>
 </div>


</form>
</div></div>
<div class="footer" >
<button class="btn btn-info " type="button" onclick="sub_idcard_img()" >提交</button>
  <button class="btn btn-default bt_close" type="button" onclick="close_dialog()" >关闭</button>
</div>
</block>

<block name="script">

  <script type="text/javascript">
    var idcard_http = 0;
    var idcard_img = 0;
     _hide_public_loading();
    function close_dialog(){
     art.dialog({title:'温馨提示',content: '<span>确认取消本次身份证上传？</span>', ok: function () {art.dialog.open.api.close();return false;},okval:'确定',cancelVal: '取消',cancel: true});
     return false;
   }


   $(function () {  

     $("#f").change(function () {
      var $this = $(this);
      var file = this.files[0];
      var fd = new FormData(document.getElementById("card_form"));
      fd.append('file', file);
      _show_public_loading();
      $.ajax({
        url: "{:U('Order/uploadIdrd')}",
        type: "post",
        dataType: "json",
        data:fd,
        processData: false,  // 告诉jQuery不要去处理发送的数据
        contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {  
            if(data.state ==1){
               idcard_img = 1;
               $('#idcard_img').val(window.location.host+data.url);
               $('.just').html('<img width="180px" height="180px" src=./'+data.url+'>');
             
            }
            _hide_public_loading();
        },
        error:function(e){
          console.log('网络错误');
        }
        ,complete: function () {
                  _hide_public_loading();
             }
      })

    });  


     $("#f2").change(function () {
      var $this = $(this);
      var file = this.files[0];
      var fd = new FormData(document.getElementById("card_form"));
      fd.append('file', file);
      _show_public_loading();
      $.ajax({
        url: "{:U('Order/uploadIdrd')}",
        type: "post",
        dataType: "json",
        data:fd,
                    processData: false,  // 告诉jQuery不要去处理发送的数据
                    contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
        success: function (data) {  
            if(data.state ==1){
               $('#idcardanti_img').val(window.location.host+data.url);
               $('.back').html('<img width="180px" height="180px" src=./'+data.url+'>');

            }
            _hide_public_loading();
        },
         error:function(e){
          console.log('网络错误');
        }
        ,complete: function () {
                  _hide_public_loading();
             }
       })

    });  
   });

var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"} 

function isCardID(sId){
 var iSum=0 ;
 var info="" ;
 if(!/^\d{17}(\d|x)$/i.test(sId)) /*return "你输入的身份证长度或格式错误"*/ return false;
 sId=sId.replace(/x$/i,"a");
 if(aCity[parseInt(sId.substr(0,2))]==null) /*return "你的身份证地区非法" */ return false;
 sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
 var d=new Date(sBirthday.replace(/-/g,"/")) ;
 if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))/*return "身份证上的出生日期非法"*/ return false;
 for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11) ;
 if(iSum%11!=1) /*return "你输入的身份证号非法"*/ return false;
 //aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女");//此次还可以判断出输入的身份证号的人性别
 return true;
}
//验证身份证
function check_old_pwd(_this){
  var idcard = $(_this).val();
  var res = isCardID(idcard);
  if(!res){
         // showvfmsg(0, '密码格式错误！', 1900);
         $(_this).parent().children('span').show();
         $(_this).parent().children('span').html('<i class="icon-remove red"></i>');
         return false;
       }else{
        idcard_http = 1;
        $(_this).parent().children('span').show();
        $(_this).parent().children('span').html('<i class="icon-ok green"></i>');
      }


    }


    function isCardNo(card) { 
     var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
     return pattern.test(card); 
   } 

  //提交身份证信息
   function sub_idcard_img(){
      if(idcard_http != 1){
         showvfmsg('0','请填写正确的身份证',2000);return false;
      }
      if(idcard_img != 1){
         showvfmsg('0','请上传身份证图片',2000);return false;
      }
      var data = $('#card_form').serialize();
      var url = "{:U('Order/uploadIdrd_http')}";
      _show_public_loading();
      $.ajax({
        url: url,
        type: "post",
        dataType: "json",
        data:data,
        success: function (data) {  
            var retstatus = data.state == 1 ? "1" : "0";
            showvfmsg(retstatus, data.msg, 1900);
            _hide_public_loading();
            if(retstatus == 1){
              setTimeout(function(){art.dialog.open.api.close();return false;},2000) 
              }

        },
         error:function(e){
          console.log('网络错误');
        }
       })
   }
 </script>
</block>
